{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ac82e26e-c981-40c5-992c-4e698a04af42",
   "metadata": {},
   "source": [
    "## u2net"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bdeec8d8-6e0e-40ce-9173-ac87499058c6",
   "metadata": {},
   "source": [
    "- https://github.com/xuebinqin/U-2-Net"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "327a78a1-96e8-48b0-bfce-8f8135718bd6",
   "metadata": {},
   "source": [
    "### human portrait"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dcda27c5-d2b7-4795-8871-e9a8597571c6",
   "metadata": {},
   "source": [
    "- `python u2net_portrait_composite.py -s 20 -a 0.5`\n",
    "    - -s indicates the sigma of gaussian function for blurring the orignal image\n",
    "    - -a denotes the alpha weights of the orignal image when fusing them.\n",
    "    - 代码层面要修改\n",
    "        - `im_comp = im_comp.astype(np.uint8)`（增加这一步处理，适配新版本的 pillow？）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "298c3c49-4566-4295-90b5-e2c7c3ecf55d",
   "metadata": {},
   "source": [
    "### human segmentation"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0450941b-d491-445e-8b49-df32925166ac",
   "metadata": {},
   "source": [
    "- `python u2net_human_seg_test.py`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14fa93d2-1c9d-4323-b870-512bfe9c400b",
   "metadata": {},
   "source": [
    "## rembg"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e69eda4-2d17-4995-94e6-dcc8622e039d",
   "metadata": {},
   "source": [
    "- `pip install \"rembg[gpu,cli]\"`\n",
    "    - 注意 onnxruntime-gpu 的版本兼容性问题\n",
    "        - `pip install onnxruntime-gpu==1.11`\n",
    "        - `pip install onnxruntime-gpu==1.12`\n",
    "        - https://onnxruntime.ai/docs/execution-providers/TensorRT-ExecutionProvider.html#requirements\n",
    "- https://github.com/danielgatis/rembg\n",
    "    - Rembg is a tool to remove images background "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a8e8309b-4be6-4167-a54d-009144203cff",
   "metadata": {},
   "source": [
    "- rembg i path/to/input.png path/to/output.png\n",
    "- rembg i -m u2netp path/to/input.png path/to/output.png\n",
    "    - 内部使用的也是 u2net"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
